package cn.kgc.service.impl;

import cn.kgc.bean.dto.UserDto;
import cn.kgc.bean.pojo.CUser;
import cn.kgc.mapper.GMUserMpaaer;
import cn.kgc.service.GMUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GMUserServiceImpl extends ServiceImpl<GMUserMpaaer,CUser> implements GMUserService {

    @Autowired
    private GMUserMpaaer gmUserMpaaer;

    @Override
    public List<UserDto> selectAllCuser() {
        return gmUserMpaaer.selectAllCuser();
    }
    //新增用户并加密
    @Override
    public CUser addCUser(CUser cUser) {
        //shiro的加密方式 最后一位是盐值
        SimpleHash md5 = new SimpleHash("MD5",cUser.getPassword(),"salt",3);
        String newPassword = md5.toHex();
        cUser.setPassword(newPassword);
        this.gmUserMpaaer.addCUser(cUser);
        return cUser;
    }


    //修改用户并加密密码
    @Override
    public CUser updateCUserByworkId(CUser cUser) {
        SimpleHash md5 = new SimpleHash("MD5",cUser.getPassword(),"salt",3);
        String newPassword = md5.toHex();
        cUser.setPassword(newPassword);
        this.gmUserMpaaer.updateCUserByworkId(cUser);
        return cUser;
    }


    //删除用户
    @Override
    public int deleteCUserByworkId(Long id) {
        return gmUserMpaaer.deleteCUserByworkId(id);
    }

    @Override
    public List<CUser> selectList(List<UserDto> list) {
        return gmUserMpaaer.selectList(list);
    }
}
